<?php namespace WoXuanWang\Dashboard\Controllers;

use WoXuanWang\Dashboard\Repositories\DashboardRepository;
use WoXuanWang\ActionLog\Repositories\ActionLogRepository;
use WoXuanWang\Dashboard\Requests\SetImageRequest;
use WoXuanWang\Settings\Repositories\SettingsRepository;
use Illuminate\Http\Request;
use zgldh\Scaffold\AppBaseController;

class DashboardController extends AppBaseController
{

    public function __construct()
    {
        $this->middleware("auth");
    }

    /**
     * Display a listing of the Certificate.
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(Request $request)
    {
        ActionLogRepository::log("查看", "总览(dashboard):", \Auth::user());
        return view('WoXuanWang\Dashboard::index');
    }

    public function settings()
    {
        $settingsRepo = app(SettingsRepository::class);
        $settingKey = $settingsRepo->getDashboardSettingKey();
        $grids = $settingsRepo->getDashboardGrids($settingKey);
        $settings = compact('grids');
        return $this->sendResponse($settings, 'successfully');
    }

    public function setImage(SetImageRequest $request)
    {
        ActionLogRepository::log("编辑", "总览(dashboard)图片:", \Auth::user());
        $dashboardRepository = app(DashboardRepository::class);
        $dashboardRepository->setImageAtPosition($request->get('position'), $request->get('upload_id'));
        return $this->sendResponse(null, 'successfully');
    }
}
